<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    :close-on-click-modal="false"
    width="400px"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="要货日期" prop="deliveryDate">
        <el-date-picker
          v-model="form.deliveryDate"
          align="right"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>

import { updateDeliveryDate } from '@/api/order'

export default {
  name: 'DatePicker',
  data() {
    return {
      form: {
        id: '',
        deliveryDate: null,
      },
      order:null,
      rules: {
        deliveryDate: [
          { required: true, trigger: 'blur', message: '请输入要货日期' },
        ]
      },
      title: '',
      minDate:'',
      dialogFormVisible: false,
    }
  },
  created() {},
  methods: {
    showEdit(row) {
     this.title = '修改要货日期'
     this.order = row.orderDetailEntities
      let res = this.$baseLodash.map(row.orderDetailEntities,'deliveryDate');
      if(res.length > 0){
        this.form.deliveryDate = res[0]
        this.form.id = row.id
      }
       this.dialogFormVisible = true
    },
    close() {
      //this.$refs['form'].resetFields()
      //this.form = this.$options.data().form
      this.dialogFormVisible = false
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          let msg = ''
          msg = '要货日期修改成功'
          await updateDeliveryDate(this.form)
          this.$baseMessage(msg, 'success')
          this.$emit('fetch-data')
          //回更订单详细数据
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
